package com.apollographql.apollo;

import com.apollographql.apollo.api.Operation;
import com.apollographql.apollo.exception.ApolloCanceledException;
import com.apollographql.apollo.exception.ApolloException;
import com.apollographql.apollo.exception.ApolloHttpException;
import com.apollographql.apollo.exception.ApolloNetworkException;
import com.apollographql.apollo.internal.util.Cancelable;
import okhttp3.Response;

public interface ApolloPrefetch extends Cancelable {

    public interface Factory {
        <D extends Operation.Data, T, V extends Operation.Variables> ApolloPrefetch prefetch(Operation<D, T, V> operation);
    }

    @Override // com.apollographql.apollo.internal.util.Cancelable
    void cancel();

    ApolloPrefetch clone();

    void enqueue(Callback callback);

    Operation operation();

    public static abstract class Callback {
        public abstract void onFailure(ApolloException apolloException);

        public abstract void onSuccess();

        public void onHttpError(ApolloHttpException e) {
            onFailure(e);
            Response response = e.rawResponse();
            if (response != null) {
                response.close();
            }
        }

        public void onNetworkError(ApolloNetworkException e) {
            onFailure(e);
        }

        public void onCanceledError(ApolloCanceledException e) {
            onFailure(e);
        }
    }
}
